<?php

namespace app\admin\controller\wdsxh\mall;

use app\admin\model\wdsxh\mall\Express;
use app\admin\model\wdsxh\mall\Item;
use app\admin\model\wdsxh\mall\Logistics;
use app\admin\model\User;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;

/**
 * 【订单表】
 *
 * @icon fa fa-circle-o
 */
class Order extends Backend
{
    
    /**
     * Order模型对象
     * @var \app\admin\model\wdsxh\mall\Order
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\wdsxh\mall\Order;
        if ($this->auth->id == 1) {
            $expressObj = (new Express())->where('store_id','-1')->select();
        } else {
            $expressObj = (new Express())->where('admin_id',$this->auth->id)->select();
        }
        $this->view->assign('expressObj',$expressObj);
        $this->view->assign("buyNowList", $this->model->getBuyNowList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("refundStatusList", $this->model->getRefundStatusList());
        $this->view->assign("paidList", $this->model->getPaidList());
    }

    public function import()
    {
        parent::import();
    }

    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    //订单详情
    public function goods_details($ids = null){
        $orderObj = $this->model->get($ids);
        $usermodel = (new User())->where('id',$orderObj['user_id'])->find();
        $logisticsModel = (new Logistics())->where('order_id',$orderObj['id'])->find();
        $goodsObj = (new Item())->where('order_id',$orderObj['id'])->select();
        $refundMode = (new \app\admin\model\wdsxh\mall\Refund())->where('order_id',$orderObj['id'])->find();
        $this->view->assign("refundMode", $refundMode);
        $this->view->assign("goodsObj", $goodsObj);
        $this->view->assign("usermodel", $usermodel);
        $this->view->assign("orderObj", $orderObj);
        $this->view->assign("logisticsModel", $logisticsModel);
        return $this->view->fetch();

    }

}


